package com.jeson.sacred;

import java.util.Timer;
import java.util.TimerTask;

public class GenericJVMMemory extends TimerTask {
	
	private static GenericJVMMemory genericJVMMemory;
	private GenericJVMMemory() {}
	public static synchronized GenericJVMMemory getInstance(){
		if (genericJVMMemory==null) {
			genericJVMMemory=new GenericJVMMemory();
			genericJVMMemory.setTimeOut();
		}
		return genericJVMMemory;
	}
	@Override
	public void run() {
		Runtime runtime = Runtime.getRuntime();
		System.out.println("maxMemory最大使用内存量:"+(runtime.maxMemory()/(1024*1024))+"M,freeMemory空闲内存量:"+(runtime.freeMemory()/(1024*1024))+"M,totalMemory内存总量:"+(runtime.totalMemory()/(1024*1024))+"M");
	}
	private void setTimeOut(){
		Timer timer=new Timer();
		timer.schedule(this,0,1000);
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		GenericJVMMemory.getInstance();
	}

}
